<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Stores a string of bytes in the database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.remove.html">MongoGridFS::remove</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.storefile.html">MongoGridFS::storeFile</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongogridfs.storebytes" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoGridFS::storeBytes</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.2)</p><p class="refpurpose"><span class="refname">MongoGridFS::storeBytes</span> &mdash; <span class="dc-title">Stores a string of bytes in the database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongogridfs.storebytes-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>MongoGridFS::storeBytes</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$bytes</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$metadata</code><span class="initializer"> = array()</span></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span>
  ]] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongogridfs.storebytes-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
  <dl>

   
    <dt>

     <em><code class="parameter">bytes</code></em>
    </dt>

    <dd>

     <p class="para">
      String of bytes to store.
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">metadata</code></em>
    </dt>

    <dd>

     <p class="para">
      Other metadata fields to include in the file document.
     </p>
     <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">These fields may also overwrite those that would be created automatically by the driver, as described in the MongoDB core documentation for the <a href="http://docs.mongodb.org/manual/core/gridfs/#the-files-collection" class="link external">&raquo;&nbsp;files collection</a>. Some practical use cases for this behavior would be to specify a custom <em>chunkSize</em> or <em>_id</em> for the file.</p></p></blockquote>
    </dd>

   
   
    <dt>

     <em><code class="parameter">options</code></em>
    </dt>

    <dd>

     <p class="para">
      Options for the store.
      <ul class="itemizedlist">
       <li class="listitem"><p class="para"><em>&quot;w&quot;</em></p><p class="para">See <a href="mongo.writeconcerns.html" class="link">WriteConcerns</a>. The default value for <a href="class.mongoclient.html" class="classname">MongoClient</a> is <em>1</em>.</p></li>
      </ul>
     </p>
    </dd>

   
  </dl>

 </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongogridfs.storebytes-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">Returns the <em>_id</em> of the saved file document. This will be a generated <a href="class.mongoid.html" class="classname">MongoId</a> unless an <em>_id</em> was explicitly specified in the <em><code class="parameter">extra</code></em> parameter.</p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongogridfs.storebytes-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if the &quot;w&quot; option is set and the write fails.</p><p class="para">Throws <a href="class.mongocursortimeoutexception.html" class="classname">MongoCursorTimeoutException</a> if the &quot;w&quot; option is set to a value greater than one and the operation takes longer than <var class="varname"><var class="varname">MongoCursor::$timeout</var></var> milliseconds to complete.  This does not kill the operation on the server, it is a client-side timeout. The operation in <em>MongoCollection::$wtimeout</em> is milliseconds.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongogridfs.storebytes-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1475">
   <p><strong>Example #1 <span class="function"><strong>MongoGridFS::storeBytes()</strong></span> with additional metadata</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$gridfs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">selectDB</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getGridFS</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$bytes&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'abcdefghijklmnopqrstuvwxyz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gridfs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">storeBytes</span><span style="color: #007700">(</span><span style="color: #0000BB">$bytes</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'_id'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'alphabet'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$gridfsFile&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$gridfs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$gridfsFile</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(7) {
  [&quot;_id&quot;]=&gt;
  string(8) &quot;alphabet&quot;
  [&quot;uploadDate&quot;]=&gt;
  object(MongoDate)#7 (0) {
  }
  [&quot;length&quot;]=&gt;
  int(26)
  [&quot;chunkSize&quot;]=&gt;
  int(262144)
  [&quot;md5&quot;]=&gt;
  string(32) &quot;c3fcd3d76192e4007dfb496cca67e13b&quot;
}
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongogridfs.storebytes-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="mongogridfs.put.html" class="function" rel="rdfs-seeAlso">MongoGridFS::put()</a> - Stores a file in the database</span></li>
   <li class="member"><span class="function"><a href="mongogridfs.storefile.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeFile()</a> - Stores a file in the database</span></li>
   <li class="member"><span class="function"><a href="mongogridfs.storeupload.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeUpload()</a> - Stores an uploaded file in the database</span></li>
   <li class="member">MongoDB core docs on <a href="http://docs.mongodb.org/manual/core/gridfs/" class="link external">&raquo;&nbsp;GridFS</a></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.remove.html">MongoGridFS::remove</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.storefile.html">MongoGridFS::storeFile</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
